const FileType = {
  folder: "folder",
  note: "note",
  img: "img",
}
const user = JSON.parse(sessionStorage.getItem('user'));

const NewFileByType = {
  folder: {fileName: "新建文件夹", fileType: FileType.folder, fileTypeName: "文件夹", newFileTitle: '新建文件夹'},
  note: {fileName: "新建笔记", fileType: FileType.note, fileTypeName: "笔记", newFileTitle: '新建笔记'},
}

class File {

  static className() {
    return 'File';
  }

  constructor(folderName, fileType, fileTypeName,  newFileTitle = '新建文件',parentFolderId = 0, userId = user.userId,username = user.username) {
    this.fileName = folderName;
    this.fileType = fileType;
    this.fileTypeName = fileTypeName;
    this.newFileTitle = newFileTitle;
    this.parentFolderId = parentFolderId;
    this.userId = userId || null;
    this.username = username || null;
    this.createdTime = new Date();
  }

  static newFileByType(type, parentFolderId) {
    return new File(NewFileByType[type].fileName, NewFileByType[type].fileType, NewFileByType[type].fileTypeName, NewFileByType[type].newFileTitle, parentFolderId);
  }

  static create(folderName, fileType, fileTypeName, parentFolderId) {
    return new File(folderName, fileType, fileTypeName, parentFolderId);
  }
}

export {
  FileType,
  File
};
